import org.aceor.mddal.common.constants.Constants;
import org.aceor.mddal.common.zk.DynConfigClient;
import org.aceor.mddal.common.zk.DynConfigClientFactory;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;

/**
 * Created by lxue on 16/3/19.
 */
public class Main {
    public static void main1(String[] args){
        CuratorFramework zkClient = CuratorFrameworkFactory.newClient(
                Constants.DEFAULT_ZK_DOMAIN_NAME
//                "127.0.0.1"
                        +":"+Constants.DEFAULT_ZK_CLIENT_PORT,
                new ExponentialBackoffRetry(Constants.DEFAULT_ZK_BASE_SLEEP_TIME, 1));
        zkClient.start();
        try {
            System.out.println("ZkClient start!");
            zkClient.blockUntilConnected();
            System.out.println("ZkClient Connected!");
            zkClient.create().creatingParentContainersIfNeeded().forPath("/configs/test/zk-domain","zk.mddal.aceor.org".getBytes(Constants.DEFAULT_CHARSET));
            System.out.println(new String(zkClient.getData().forPath("/configs/test/zk-domain"), Constants.DEFAULT_CHARSET));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args){
        DynConfigClient configClient = DynConfigClientFactory.getConfigClient();
//        configClient.registerListener("test", "zk-domain", new ConfigChangeListener() {
//            @Override
//            public Executor getExecutor() {
//                return Executors.newSingleThreadExecutor();
//            }
//
//            @Override
//            public void receiveConfig(ConfigDTO configDTO) {
//            }
//        });
        try {
//            configClient.setConfig("/configs/sequence/127.0.0.1","0");
//            System.out.println(configClient.getConfig("sequence","121.42.50.115"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
